﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace temportal
{
    class GameInput
    {
        Dictionary<string, Input> mInputs = new Dictionary<string, Input>();
        
        public GameInput()
        {
        }

        /// <summary>
        /// Add an Action if it doesn't already exist
        /// </summary>
        /// <param name="theAction"></param>
        /// <returns></returns>
        public Input MyInput(string theAction)
        {
            if (mInputs.ContainsKey(theAction) == false)
                mInputs.Add(theAction, new Input());
            return mInputs[theAction];
        }

        public void BeginUpdate()
        {
            Input.BeginUpdate();
        }

        public void EndUpdate()
        {
            Input.EndUpdate();
        }

        public bool IsPressed(string theAction, PlayerIndex thePlayer)
        {
            if (mInputs.ContainsKey(theAction) == false)
                return false;
            return mInputs[theAction].IsPressed(thePlayer);
        }

        public void AddGamePadInput(string theAction, Buttons theButton, bool isReleasedPreviously)
        {
            MyInput(theAction).AddGamepadInput(theButton, isReleasedPreviously);
        }

        public void AddKeyboardInput(string theAction, Keys theKey, bool isReleasedPreviously)
        {
            MyInput(theAction).AddKeyboardInput(theKey, isReleasedPreviously);
        }
    }
}
